package com.zuqiuzhandui.liveing.util;

import com.code19.library.DensityUtil;
import com.code19.library.L;
import com.zuqiuzhandui.liveing.common.MyApplication;
import com.zuqiuzhandui.liveing.myInterfacce.Constant;


/**
 * @author MC
 *         Description  根据七牛的api加工合适尺寸的图片
 * @date 创建时间 2016-08-05
 */
public class ImageUrlUtil {
    public static String processUrl(float x, float y, String imgUrl) {
        StringBuilder stringBuffer = new StringBuilder();
        int pxX = DensityUtil.dip2px(MyApplication.getInstance(), x);
        int pxY = DensityUtil.dip2px(MyApplication.getInstance(), y);
        if (pxX != 0 && pxY != 0) {
            stringBuffer
                    .append(Constant.BASE_QINIU)
                    .append(imgUrl).append("?imageView2/")
                    .append("1/w/")
                    .append(pxX)
                    .append("/")
                    .append("h/")
                    .append(pxY);
        }
        L.d("qiniuUrl:  "+stringBuffer.toString());
        return stringBuffer.toString();
    }

    /**
     * @param x      px
     * @param y      px
     * @param imgUrl
     * @return
     */
    public static String processUrl2(float x, float y, String imgUrl) {
        StringBuilder stringBuffer = new StringBuilder();
        int pxX = DensityUtil.dip2px(MyApplication.getInstance(), x);
        int pxY = DensityUtil.dip2px(MyApplication.getInstance(), y);
            if (y==0){
                stringBuffer.append(Constant.BASE_QINIU).append(imgUrl).append("?imageView2/")
                        .append("0/w/")
                        .append(((int) x))
                        ;
            }else {
                stringBuffer.append(imgUrl).append("?imageView2/")
                        .append("0/w/")
                        .append(((int) x))
                        .append("/")
                        .append("h/")
                        .append(y);
            }

        return stringBuffer.toString();
    }


}
